package cpu.footprint.common;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import org.xutils.x;

import cpu.footprint.R;
import cpu.footprint.api.MyApplication;
import cpu.footprint.util.DialogUtil;

/**
 * 基础activity
 * Created by WJP on 2017/10/13.
 */

public class BaseActivity extends AppCompatActivity {
    protected Context mContext;//上下文
    protected Dialog mDialog;
    protected MyApplication myApplication;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        mContext = this;
        mDialog=showLoadingDialog(this);
        myApplication = (MyApplication) getApplication();
        //MyApplication.getInstance().addActivity(this);
    }
    public Dialog showLoadingDialog(AppCompatActivity context){
        // 创建Dialog并传递style文件
//        final Dialog dialog = new Dialog(context, R.style.dialog);
//        // 设置它的ContentView
//        dialog.setContentView(R.layout.loading_dialog);
//        return dialog;
        final Dialog  mDialog = DialogUtil.getLoadDialog(context,"加载中...");
        mDialog.setCancelable(true);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                //mHandler.removeCallbacksAndMessages(null);
                mDialog.dismiss();
            }
        });
        return mDialog;
    }
    public void Toast(String text){
        Toast.makeText(this,text,Toast.LENGTH_SHORT).show();
    }
    @Override
    protected void onDestroy() {
        //MyApplication.getInstance().finishActivity(this);
        super.onDestroy();
    }
}
